#测试论坛主页
import time

from selenium.webdriver.common.by import By

from commond.Utils import ForumDriver
from Test.ForumLoginTest import Login
class ForumList:
    url = ""
    driver = ""
    def __init__(self):
       self.driver=ForumDriver.driver
       self.url="http://127.0.0.1:9580/index.html"
       self.driver.get(self.url)

    def Fail_List(self):
        self.url="http://127.0.0.1:9580/index.html"
        self.driver.get(self.url)
        #未登陆情况下直接返回登陆页面,判断是否返回了登陆页面，直接检查登陆界面元素
        Login.Check_Ele_Login()

    #检查头部导航条
    def Check_Head(self):
        #导航左侧logo按钮
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > h1 > a > img")
        #输入框
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div.nav-item.d-none.d-md-flex.me-3 > div > form > div > input")
        #模式切换
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > a.nav-link.px-0.hide-theme-dark > svg")
        #通知
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > div > a > svg")
        #用户身份
        self.driver.find_element(By.CSS_SELECTOR,"#index_nav_avatar")

        #检测模式切换
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > a.nav-link.px-0.hide-theme-dark > svg").click()
        time.sleep(1)
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > a.nav-link.px-0.hide-theme-light > svg").click()
        time.sleep(0.5)

    #论坛导航条测试
    def Check_middle(self):
        #首页
        self.driver.find_element(By.CSS_SELECTOR,"#nav_board_index > a > span.nav-link-title")
        #JAVA
        self.driver.find_element(By.CSS_SELECTOR,"#topBoardList > li:nth-child(2) > a > span.nav-link-title")
        #C++
        self.driver.find_element(By.CSS_SELECTOR,"#topBoardList > li:nth-child(3) > a > span.nav-link-title")
        #MySQL
        self.driver.find_element(By.CSS_SELECTOR,"#topBoardList > li:nth-child(5) > a > span.nav-link-title")
        #“发布帖子”按钮
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post")

    def Check_pos(self):
        # 帖子：以MySQL模块中mxj测试这帖子为例,首页显示的帖子应该有标题，时间，浏览量
        self.driver.find_element(By.CSS_SELECTOR,"#topBoardList > li.nav-item.active > a").click()
        self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div:nth-child(1) > div > div.col > div.text-truncate > a > strong")
        self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div:nth-child(1) > div > div.col > div.text-muted.mt-2 > div > div.col > ul > li:nth-child(2)")
        self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div:nth-child(1) > div > div.col > div.text-muted.mt-2 > div > div.col-auto.d-none.d-md-inline > ul > li:nth-child(1)")

    #检查版权信息
    def Check_Last(self):
        text=self.driver.find_element(By.CSS_SELECTOR,"#page-wrapper > footer").text
        print(text)

    #点击帖子进入帖子详情页
    def List_to_Detail(self):
        #进入MySQL板块
        self.driver.find_element(By.CSS_SELECTOR,"#topBoardList > li:nth-child(5) > a > span.nav-link-title").click()
        time.sleep(3)
        ForumDriver.getScreenshot()
        self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div:nth-child(1) > div > div.col > div.text-truncate > a > strong").click()


List=ForumList()